# Copyright (c) Open-MMLab. All rights reserved.
import time

from .hook import Hook


class IterTimerHook(Hook):

    def before_epoch(self, runner):
        self.t = time.time()
        self.skip_step = 0
        self.time_all = 0

    def before_iter(self, runner):
        runner.log_buffer.update({'data_time': time.time() - self.t})

    def after_iter(self, runner):
        runner.log_buffer.update({'time': time.time() - self.t})
        # fox:临时保存时间
        curr_time = self.t
        self.t = time.time()
        if self.skip_step >= 5:
            self.time_all += self.t - curr_time
        # else:
        #     print("FOX_LOG skip_test:", self.skip_step)
        self.skip_step += 1
